/***********************************************************************
 * Module:  Departement.java
 * Author:  Alexandro
 * Purpose: Defines the Class Departement
 ***********************************************************************/

package dao;

import java.util.*;
import java.sql.*;

public class Departement extends Codage implements InterfaceDAO {
   public Filiere[] filiere;
   
   public int nbEtudiants() {
      // TODO: implement
      return 0;
   }
   
   public int insert(int[] param) {
      
        try {			
			dao.DAODataConnection.executer("INSERT INTO departement VALUES("+getCode()+",'"+getLibelle()+"');");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public Object[] select(int[] param) {
      
      try {			
			
			ResultSet table = dao.DAODataConnection.executerQuery("SELECT * FROM departement");								
			int max = 10;
			Departement[] sortie = new Departement[max];
			int i=0;
			while(table.next() && i<max)	
			{
				Departement neuf = new Departement();
				neuf.setCode(table.getInt(1));
				neuf.setLibelle(table.getString(2));
				sortie[i]=neuf;
				i++;
			}		
			return sortie;			
			}
		catch(Exception e){ System.out.println(e); }		
		
		return null;
   }
   
   public int delete(int[] param) {
      try {			
			dao.DAODataConnection.executer("DELETE FROM departement WHERE code_dep="+getCode());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
   }
   
   public int update(int[] param) {
        
        try {			
			dao.DAODataConnection.executer("UPDATE departement SET libelle='"+getLibelle()+"' where code_dep="+getCode());											
			return 0;			
			}
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
   }

}